import { ref } from 'vue';
import dayjs from 'dayjs';
import { useAuthStore } from '@/store/modules/auth';

const lotType = ref('searchInput');
const lotids = ref([]);
const moduleNoSearchData = ref(null);
const authStore = useAuthStore();

export default {
  url: '/qms/dryFilm/redo/list',
  addUrl: '/qms/dryFilm/redo/add',
  editUrl: '/qms/dryFilm/redo/update',
  delUrl: '/qms/dryFilm/redo/deleteBatch',
  searchFormList: [
    {
      type: 'input',
      key: 'moduleNo',
      label: '重工料号',
      placeholder: '请输入重工料号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 5
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'select',
      key: 'state',
      label: '审核状态',
      placeholder: '请选择审核状态',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 5,
      selectOptions: [
        {
          value: '0',
          label: '待领班审核'
        },
        {
          value: '1',
          label: '待修改'
        },
        {
          value: '2',
          label: '待主管审核'
        },
        {
          value: '3',
          label: '审核完成'
        }
      ]
    },
    {
      type: 'dateRangePicker',
      key: 'time',
      label: '日期',
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 6
    }
  ],
  searchParam: ref({
    moduleNo: null,
    state: null,
    time: null
  }),
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'operatorTime',
      dataIndex: 'operatorTime',
      title: '记录时间',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'state',
      dataIndex: 'state',
      title: '审核状态',
      width: 120,
      align: 'center',
      checked: true,
      fixed: 'left',
      ellipsis: true,
      customRender: ({ record }) => {
        return ['待领班审核', '待修改', '待主管审核', '审核完成'][record.state];
      }
    },
    {
      key: 'dryFilmStation',
      dataIndex: 'dryFilmStation',
      title: '站点',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'moduleNo',
      dataIndex: 'moduleNo',
      title: '重工料号',
      width: 150,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'batchNum',
      dataIndex: 'batchNum',
      title: '批量',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'quantity',
      dataIndex: 'quantity',
      title: '重工数量PNL',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'redoReason',
      dataIndex: 'redoReason',
      title: '重工原因',
      width: 240,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'redoCounts',
      dataIndex: 'redoCounts',
      title: '重工次数',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'checkResult',
      dataIndex: 'checkResult',
      title: '重工后判定',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'afterChecker',
      dataIndex: 'afterChecker',
      title: '品质签名确认',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'operator',
      dataIndex: 'operator',
      title: '生产签名确认',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foreman',
      dataIndex: 'foreman',
      title: '领班审核',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'foremanTime',
      dataIndex: 'foremanTime',
      title: '领班审核时间',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examiner',
      dataIndex: 'examiner',
      title: '主管审核',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'examinerTime',
      dataIndex: 'examinerTime',
      title: '主管审核时间',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'remark',
      dataIndex: 'remark',
      title: '备注',
      width: 200,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'createTime',
      dataIndex: 'createTime',
      title: '创建时间',
      width: 150,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    // 创建人修改成为生产签名确认
    {
      key: 'updateTime',
      dataIndex: 'updateTime',
      title: '修改时间',
      width: 180,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'updateBy',
      dataIndex: 'updateBy',
      title: '修改人',
      width: 100,
      align: 'center',
      checked: true,
      ellipsis: true
    }
  ],

  scroll: { x: 2500, y: 'auto' },
  topFormList: [
    // 用于获取model
    {
      type: 'getModel',
      hidden: true,
      handle(topModel, personModle) {
        topFormModel = topModel;
        bottomFormModel = personModle;
      }
    },
    {
      type: 'datePicker',
      key: 'operatorTime',
      label: '时间',
      span: 8,
      rule: {
        required: true,
        message: '请选择录入时间',
        trigger: 'change'
      },
      defaultValue: dayjs().format('YYYY-MM-DD HH:mm:ss'),
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      showTime: true
    },
    {
      type: 'input',
      key: 'dryFilmStation',
      label: '站点',
      span: 8,
      rule: {
        required: true,
        message: '请输入站点',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'moduleNo',
      label: '重工料号',
      span: 8,
      rule: {
        required: true,
        message: '请输入重工料号',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'batchNum',
      label: '批量',
      span: 8,
      rule: {
        required: true,
        message: '请输入批量',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'input',
      key: 'quantity',
      label: '重工数量',
      span: 8,
      rule: {
        required: true,
        message: '请输入重工数量',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'redoReason',
      selectType: 'select',
      label: '重工原因',
      span: 8,
      rule: {
        required: true,
        message: '请填写重工原因',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },

    {
      type: 'input',
      key: 'redoCounts',
      label: '重工次数',
      defaultValue: 1,
      span: 8,
      rule: {
        required: true,
        message: '请填写重工次数',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'radio',
      key: 'checkResult',
      label: '判定',
      span: 8,
      rule: {
        required: true,
        message: '请选择判定结果',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      selectOptions: [
        {
          label: 'OK',
          value: 'OK'
        },
        {
          label: 'NG',
          value: 'NG'
        }
      ]
    },
    {
      type: 'input',
      key: 'afterChecker',
      selectType: 'select',
      label: '品质签名确认',
      defaultValue: '曹杰云',
      span: 8,
      rule: {
        required: true,
        message: '请填写品质签名',
        trigger: 'change'
      },
      tansfromDisabled(operateType) {
        return operateType === 'look';
      }
    },
    {
      type: 'textarea',
      key: 'remark',
      label: '备注',
      tansfromDisabled(operateType) {
        return operateType === 'look';
      },
      textareaRows: 1,
      span: 24
    }
  ],
  bottomList: [
    {
      type: 'input',
      key: 'operator',
      label: '生产签名确认',
      defaultValue: authStore.userInfo.user.nickName || authStore.userInfo.user.userName,
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'foreman',
      label: '领班审核',
      disabled: true,
      span: 8
    },
    {
      type: 'input',
      key: 'examiner',
      label: '主管审核',
      disabled: true,
      span: 8
    }
  ],
  modalHeight: '80vh',
  modalClose() {
    lotType.value = 'searchInput';
    moduleNoSearchData.value = null;
    lotids.value = [];
  }
};
